<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script th:src="@{/layui/layui.all.js}"></script>
    <link  th:href="@{/layui/css/layui.css}" rel="stylesheet">
</head>
<body>
<script>
    $("#test_btn").click(function () {
        $.ajax({
            url:"/test/fragment",
            type:"GET",
            // dataType: "JSON",
            success:function(result){
                $("#test_h").html(result);
                layer.msg('123');
            }
        });
        // $("#test_h").html("123");
    });

    $(document).ready(function () {
        $.ajax({
            url:"/tCart/carts?userId=4",
            type:"POST",
            // dataType: "JSON",
            success:function(data){
                console.log(data.toString());
                if (data.length > 0 || data != null){


                    let d = "<p>123</p>"
                    $.each(data, function (i, item) {//遍历出来json数组里边的内容；i，相当于foreach的key；item，相当于foreach的value；
                        let c = "<div className=\"cart-item\">\n" +
                            "        <div className=\"thumb\">\n" +
                            "            <img className=\"w-100\" th:src=\"@{"+item.tproduct.photo+"}\" alt=\"Image-HasTech\">\n" +
                            "        </div>\n" +
                            "        <div className=\"content\">\n" +
                            "             <h5 className=\"title\"><a href=\"#/\">"+item.tproduct.title+"</a></h5>\n" +
                            "             <span className=\"product-quantity\">"+item.count+"</span>\n" +
                            "             <span className=\"product-price\">"+item.tproduct.price+"</span>\n" +
                            "             <a className=\"cart-trash\" href=\"javascript:void(0);\"><i className=\"fa fa-trash\"></i></a>\n" +
                            "        </div>\n" +
                            "   </div>";
                        console.log(i+'+++'+item.tproduct.photo);
                        $("#cart").append(c);
                    });
                }


            }
        });
        // $("#test_h").html("123");
    });
</script>
</body>
</html>